﻿
using Help;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceModel;
using System.ServiceProcess;
using System.Text; 

namespace WindowsService
{
    public partial class Service1 : ServiceBase
    {
        public Service1()
        {
            InitializeComponent();
        }
        ServiceHost host = null;//定义ServiceHost
        //为支持跨域访问建立一个支撑主机
       // ServiceHost kuayuHost = null;
        protected override void OnStart(string[] args)
        { 
            if (Help.ALL_DataV.BeganGO())
            {
                try
                {
                    WriteLog.WriteW("OnStart     1");
                    host=new ServiceHost(typeof(WcfService.Service1));
                    WriteLog.WriteW("OnStart     2");
                    host.Open();
                    WriteLog.WriteW("OnStart     3");
                }
                catch (Exception ex)
                {
                    WriteLog.WriteW("开启服务异常失败：" + ex.Message);
                }
            }
            else
            {
                OnStop();
            }
        }

        protected override void OnStop()
        {
            host.Close();
        }
    }
}
